package workflow.core;

import java.util.ArrayList;
import workflow.dto.WorkflowMessage;

public class WorkflowConditionalBlock extends WorkflowBlock {

	public WorkflowConditionalBlock() {
	}
	
	public WorkflowConditionalBlock(String name,
			WorkflowConditionElement conditionElement) {
		this.name = name;
		this.elements = new ArrayList<WorkflowElement>();
		elements.add(conditionElement);
	}

	@Override
	public int excecute() {
		outMessages = new ArrayList<WorkflowMessage>();
		WorkflowConditionElement conditionElement = 
				(WorkflowConditionElement) elements.get(0);
		conditionElement.setInMessages(inMessages);
		boolean conditionResult = conditionElement.excecute();
		outMessages.addAll(conditionElement.getOutMessages());
		return (conditionResult ? 1 : 0);
	}

}
